package com.lx.testelk.servicec.api;

import com.lx.testelk.Enums.ELKMsgCodeEnums;
import com.lx.testelk.Enums.ELKMsgTypeEnums;
import com.lx.testelk.aspect.WebLogAspect;
import com.lx.testelk.entity.ELKMessage;
import com.lx.testelk.util.MapperUtils;
import lombok.SneakyThrows;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.apache.skywalking.apm.toolkit.trace.TraceContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * TODO
 *
 * @Description
 * @Author Lx
 * @Date 2024/8/6 15:21
 **/
@RequestMapping("/serviceA")
@Controller
public class serviceApi {


    private static final Logger LOGGER = LoggerFactory.getLogger(WebLogAspect.class);

    @SneakyThrows
    @Trace
    @GetMapping("/testSky")
    public void testSky(){
//        ELKMessage msg1 = new ELKMessage().builder()
//                .Type(ELKMsgTypeEnums.ERROR.getValue())
//                .Errorcode(ELKMsgCodeEnums.one_ERROR.getValue())
//                .msg("日志信息测试")
//                .TraceId(traceId)
//                .build();

        String traceId = TraceContext.traceId();
        ELKMessage elkMessage = ELKMessage.builder()
                .Type(ELKMsgTypeEnums.ERROR.getValue())
                .Errorcode(ELKMsgCodeEnums.one_ERROR.getValue())
                .msg("serviceA日志测试")
                .TraceId(traceId)
                .build();
        String json = MapperUtils.obj2json(elkMessage);
        LOGGER.error(json);

    }
}
